#include "grflib_stdafx.h"
#include <DXUTgui.h>
#include "../include/GUIManager.h"

namespace grflib { namespace engine { namespace aux {
using namespace grflib::engine::core;

HRESULT CGUIManager::OnCreateDevice(ID3D10Device *pd3dDevice)
{
	return m_dialogResourceManager.OnD3D10CreateDevice(pd3dDevice);
}


HRESULT CGUIManager::OnResize(ID3D10Device *pd3dDevice, IDXGISwapChain *pSwapChain, const DXGI_SURFACE_DESC* pBufferSurfaceDesc)
{ 
	m_dialogResourceManager.OnD3D10ResizedSwapChain(pd3dDevice, pBufferSurfaceDesc); 
	IResizeFunc<CDialog> resizer(pd3dDevice, pSwapChain, pBufferSurfaceDesc);
	return Traverse(resizer);
}

bool CGUIManager::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HRESULT hr;
	m_dialogResourceManager.MsgProc(hWnd, uMsg, wParam, lParam);

	IMsgFunc<CDialog> msgFunc(hWnd, uMsg, wParam, lParam);
	if (E_ABORT == AbortableTraverse(msgFunc))
		return true;
	return false;
}

bool CGUIManager::AddObj(const std::string &name, boost::shared_ptr<CDialog> &pObj) //overwrite base function
{
	pObj->GetDialog().Init(&m_dialogResourceManager);
	pObj->GetDialog().SetCallback(CGUIEventManager<>::OnGUIEvent);
	return _CManagerBase<CDialog>::AddObj(name, pObj);
}

int CGUIManager::TranslateId(char *szId)
{
	id_map_type::iterator iter;
	std::string id(szId);
	if ((iter = m_ctrlIdMap.find(id)) != m_ctrlIdMap.end()) //exists
	{
		return iter->second;
	}

	//doesn't exist, create one
	m_ctrlIdMap[id] = ++m_addOnly;
	return m_addOnly;
}

}}} // namespaces